package com.example.spring.ai.tools;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.context.i18n.LocaleContextHolder;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 获取当前时区的时间工具类
 *
 * @author DuGuanghan
 * @since 2025-04-17 11:34:52
 */
public class DateTimeTools {
    @Tool(description = "获取当前时区的时间")
    String getCurrentDateTimeWithAnnotation() {
        return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
    }

    String getCurrentDateTimeWithMethodTool() {
        return LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString();
    }

    @Tool(description = "提供一个时间，为用户设置一个闹钟，给定的时间符合ISO-8601格式")
    void setAlarmWithAnnotation(String time) {
        LocalDateTime alarmTime = LocalDateTime.parse(time, DateTimeFormatter.ISO_DATE_TIME);
        System.out.println("Alarm set for " + alarmTime);
    }
}
